import numpy as np
import matplotlib.pyplot as plt

# 读取数据
data = np.loadtxt('./eos_00/result.out', skiprows=2)
# 提取x和y数据
x = data[:, 0]
y = data[:, 1]

# 进行二次方的线性拟合
coefficients = np.polyfit(x, y, 3)
fit_func = np.poly1d(coefficients)
fit_y = fit_func(x)
# 绘制原始数据和拟合曲线
plt.plot(x, y, 'o', label='no fit data', markersize=10, linewidth=2)
plt.plot(x, fit_y, label='fit with function order of tree', markersize=10, linewidth=2)
# 添加标题和标签
plt.title('Data Plot with Quadratic Fit')
plt.xlabel('VpA(A^3)')
plt.ylabel('EpA(eV)')

# 添加图例
plt.legend()

# 保存图像
plt.savefig('eos_Be16.png')